//管理员审核
// 模拟数据
const techData = [
    {
        id: 1,
        title: '京剧脸谱绘制技法',
        userName: '张艺谋',
        category: '传统戏剧/京剧',
        type: 'video',
        description: '详细介绍京剧脸谱的传统绘制技法，包括不同角色的脸谱特点...',
        materials: [
            { name: '脸谱绘制视频.mp4', url: 'https://example.com/videos/1.mp4' },
            { name: '脸谱样例1.jpg', url: 'https://example.com/images/1-1.jpg' },
            { name: '脸谱样例2.jpg', url: 'https://example.com/images/1-2.jpg' }
        ],
        status: 'pending',
        createTime: '2023-05-15 14:30:22'
    },
    {
        id: 1,
        title: '京剧脸谱绘制技法',
        userName: '张艺谋',
        category: '传统戏剧/京剧',
        type: 'video',
        description: '详细介绍京剧脸谱的传统绘制技法，包括不同角色的脸谱特点...',
        materials: [
            { name: '脸谱绘制视频.mp4', url: 'https://example.com/videos/1.mp4' },
            { name: '脸谱样例1.jpg', url: 'https://example.com/images/1-1.jpg' },
            { name: '脸谱样例2.jpg', url: 'https://example.com/images/1-2.jpg' }
        ],
        status: 'pending',
        createTime: '2023-05-15 14:30:22'
    },
    {
        id: 2,
        title: '苏绣针法',
        userName: '李子柒',
        category: '传统技艺',
        type: 'photo',
        description: '传统苏绣的各种针法展示与讲解...',
        materials: [
            { name: '苏绣图片1.jpg', url: 'https://example.com/images/suxiu1.jpg' },
            { name: '苏绣图片2.jpg', url: 'https://example.com/images/suxiu2.jpg' }
        ],
        status: 'rejected',
        createTime: '2023-05-16 09:15:33'
    },
    {
        id: 3,
        title: '蒙古长调民歌',
        userName: '张艺谋',
        category: '传统音乐',
        type: 'audio',
        description: '蒙古长调民歌的演唱技巧与特点...',
        materials: [
            { name: '长调民歌音频1.mp3', url: 'https://example.com/audios/longsong1.mp3' }
        ],
        status: 'pending',
        createTime: '2023-05-17 10:20:45'
    }
]

// 模拟获取技术列表
export const getTechList = async (params) => {
    const { page = 1, size = 10, status, category, keyword } = params

    // 筛选数据
    let filteredData = [...techData]
    if (status) {
        filteredData = filteredData.filter(item => item.status === status)
    }
    if (category) {
        filteredData = filteredData.filter(item => item.category.includes(category))
    }
    if (keyword) {
        filteredData = filteredData.filter(item =>
            item.title.includes(keyword) ||
            item.userName.includes(keyword))
    }

    // 分页
    const start = (page - 1) * size
    const end = start + size
    const paginatedData = filteredData.slice(start, end)

    return new Promise(resolve => {
        setTimeout(() => {
            resolve({
                code: 200,
                data: {
                    list: paginatedData,
                    total: filteredData.length
                }
            })
        }, 500)
    })
}

// 模拟获取技术详情
export const getTechDetail = async (id) => {
    return new Promise(resolve => {
        setTimeout(() => {
            const tech = techData.find(item => item.id === id)
            resolve({
                code: 200,
                data: tech || null
            })
        }, 300)
    })
}

// 模拟提交技术
export const submitTech = async (formData) => {
    console.log('提交的技术数据:', Object.fromEntries(formData))
    return new Promise(resolve => {
        setTimeout(() => {
            resolve({ code: 200, message: '提交成功' })
        }, 800)
    })
}

// 模拟通过审核
export const approveTech = async (id) => {
    return new Promise(resolve => {
        setTimeout(() => {
            const tech = techData.find(item => item.id === id)
            if (tech) tech.status = 'approved'
            resolve({ code: 200, message: '审核通过' })
        }, 300)
    })
}

// 模拟拒绝审核
export const rejectTech = async (id) => {
    return new Promise(resolve => {
        setTimeout(() => {
            const tech = techData.find(item => item.id === id)
            if (tech) tech.status = 'rejected'
            resolve({ code: 200, message: '已拒绝' })
        }, 300)
    })
}